import 'dart:io';

import "package:dio/dio.dart";
import 'package:flutter_shop/config/service_url.dart';

Future request(url, {formData}) async {
  Response response;
  Dio dio = new Dio();
  dio.options.contentType =
      ContentType.parse("application/x-www-form-urlencoded");

  if (formData == null) {
    response = await dio.post(servicePath[url]);
  } else {
    response = await dio.post(servicePath[url], data: formData);
  }

  if (response.statusCode == 200) {
    return response.data;
  } else {
    throw Exception('后端接口出现异常，请检测代码和服务器情况.........');
  }
}


//获取首页商城数据
Future getHomePageContent() async {
  Response response;
  Dio dio = new Dio();
  dio.options.contentType =
      ContentType.parse("application/x-www-form-urlencoded");
  var formData = {'lon': '115.02932', 'lat': '35.76189'}; //提交的参数
  response =
  await dio.post(servicePath['homePageContext'], data: formData);
  if (response.statusCode == 200) {
    return response.data;
  } else {
    throw Exception('后端接口出现异常，请检测代码和服务器情况.........');
  }
}

//商城首页热卖商品拉取
Future getHomePageBelowConten() async {
  Response response;
  Dio dio = new Dio();
  dio.options.contentType =
      ContentType.parse("application/x-www-form-urlencoded");
  int page=1;
  response = await dio.post(servicePath['homePageBelowConten'], data: page);
  if (response.statusCode == 200) {
    return response.data;
  } else {
    throw Exception('后端接口出现异常，请检测代码和服务器情况.........');
  }
}